package com.ym.controller.management;

import com.github.pagehelper.PageInfo;
import com.ym.common.enums.UserUserTypeEnum;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;

import com.ym.medical.domain.entity.DoctorDetailsEntity;
import com.ym.medical.domain.param.UserParam;
import com.ym.medical.domain.vo.DoctorVo;
import com.ym.medical.domain.vo.PatientVo;
import com.ym.medical.service.IDoctorDetailSV;
import com.ym.medical.service.IUserSV;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * 综合管理中心
 */
@Api(tags = "账号管理")
@Controller
@RequestMapping("/management/accout")
public class AccountManagement extends BaseController {
	@Autowired
	private IUserSV iUserSV;

	@Autowired
	private IDoctorDetailSV iDoctorDetailSV;

	@ApiOperation("患者账号列表")
	@GetMapping("/getPatientList")
	@ResponseBody
	public APIResponse<PageInfo<PatientVo>> getPatientList(
			@ApiParam(name = "pageNo", value = "页码", required = true)
			@RequestParam(name = "pageNo", required = true, defaultValue = "1")
					int pageNo,
			@ApiParam(name = "limit", value = "每页数量", required = false)
			@RequestParam(name = "limit", required = false, defaultValue = "10")
					int limit,
			@ApiParam(name = "blankUserSate", value = "状态值03则是黑名单列表", required = false)
					String blankUserSate,
			@ApiParam(name = "userModel", value = "用户信息", required = false)
					UserParam userModel) {
		PageInfo<PatientVo> userPageInfo = iUserSV.getPatientList(pageNo, limit, userModel, blankUserSate);
		return successData(userPageInfo);

	}

	@ApiOperation("医生账号列表")
	@GetMapping("/getDoctorList")
	@ResponseBody
	public APIResponse<PageInfo<DoctorVo>> getDoctorList(
			@ApiParam(name = "pageNo", value = "页码", required = true)
			@RequestParam(name = "pageNo", required = true, defaultValue = "1")
					int pageNo,
			@ApiParam(name = "limit", value = "每页数量", required = false)
			@RequestParam(name = "limit", required = false, defaultValue = "10")
					int limit,
			@ApiParam(name = "userModel", value = "用户信息", required = false)
					UserParam userModel) {
		PageInfo<DoctorVo> doctorVoPageInfo = iUserSV.getDoctorList(pageNo, limit, userModel);
		return successData(doctorVoPageInfo);
	}

	@ApiOperation("患者账号新增")
	@PostMapping("/addPatient")
	@ResponseBody
	public APIResponse addPatient(
			@ApiParam(name = "user", value = "用户信息", required = true)
			@RequestBody UserParam user) throws Exception {
		int rows = iUserSV.addPatient(user);
		if (rows != 1) {
			return failMsg("添加失败");
		}
		return successMsg("添加成功");

	}

	@ApiOperation("账号禁用")
	@PostMapping("/disableUser")
	@ResponseBody
	public APIResponse disableUser(
			@ApiParam(name = "userIds", value = "用户id数组", required = true)
			@RequestBody Long[] userIds) throws Exception {
		int rows = iUserSV.disableUser(userIds, UserUserTypeEnum.PATIENT);
		if (rows == 0) {
			return failMsg("操作失败");
		}
		return successMsg("操作成功");
	}

	@ApiOperation("账号启用")
	@PostMapping("/enableUser")
	@ResponseBody
	public APIResponse enableUser(
			@ApiParam(name = "userIds", value = "用户id数组", required = true)
			@RequestBody Long[] userIds) throws Exception {
		int rows = iUserSV.enableUser(userIds,UserUserTypeEnum.PATIENT);
		if (rows == 0) {
			return failMsg("操作失败");
		}
		return successMsg("操作成功");
	}

	@ApiOperation("医生账号新增")
	@PostMapping("/addDoctor")
	@ResponseBody
	public APIResponse addDoctor(
			@ApiParam(name = "userModel", value = "医生信息", required = true)
			@RequestBody UserParam userModel) throws Exception {
		int rows = iUserSV.addDoctor(userModel);
		if (rows != 1) {
			return failMsg("添加失败");
		}
		return successMsg("添加成功");

	}

	@ApiOperation("医生个人信息")
	@GetMapping("/doctorDetail")
	@ResponseBody
	public APIResponse<DoctorDetailsEntity> doctorDetail(
			@ApiParam(name = "doctId", value = "医生信息", required = true)
					Long doctId) throws Exception {
		DoctorDetailsEntity doctor = iDoctorDetailSV.selectById(doctId);
		return successData(doctor);
	}

}
